package com.wust.tieshi;

import com.wust.R;
import com.wust.baby.picture.ImageGridActivity;
import com.wust.footprint.FirstActivity;
import com.wust.menu.FirstGroupTab;
import com.wust.menu.ImageBtn;
import com.wust.menu.SecondGroupTab;

import android.app.Activity;
import android.app.TabActivity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.GestureDetector;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.Window;
import android.view.GestureDetector.OnGestureListener;
import android.view.View.OnTouchListener;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TabHost;
import android.widget.TabWidget;
import android.widget.TextView;
import android.widget.Toast;

public class charmActivity extends TabActivity implements OnTouchListener, OnGestureListener{
	private ImageBtn btn1=null;
	private TabHost tab=null;
	private static final int FLING_MIN_DISTANCE = 20;
	private static final int FLING_MIN_VELOCITY = 0;
	private GestureDetector mGestureDetector;
	@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.charmtab);
        mGestureDetector = new GestureDetector(this);
        LinearLayout ll=(LinearLayout)findViewById(R.id.linew);
		ll.setOnTouchListener(this);
		ll.setLongClickable(true);
        btn1=(ImageBtn)findViewById(R.id.btn1);
      
        tab=getTabHost();
        tab.setup();
        Intent intent1 = new Intent(this, growActivity.class);
		createTab("添加信息", intent1,R.drawable.growadd_tab);
		Intent intent2 = new Intent(this, Second.class);
		createTab("身高走势", intent2,R.drawable.growcharm);

		Intent intent3 = new Intent(this, Third.class);
		createTab("体重走势", intent3,R.drawable.growcharm);

		Intent intent4 = new Intent(this, Fourth.class);
		createTab("头围走势", intent4,R.drawable.growcharm);

		Intent intent5 = new Intent(this, Fifth.class);
		createTab("胸围走势", intent5,R.drawable.growcharm);
		
		TabWidget tabWidget = tab.getTabWidget();
		int count = tabWidget.getChildCount();
		tab.setCurrentTab(0);
    }
	private void createTab(String text, Intent intent,int drable) {
		tab.addTab(tab.newTabSpec(text).setIndicator(
				createTabView(text,drable)).setContent(intent));
	}

	private View createTabView(String text,int drawable) {
		View view = LayoutInflater.from(this).inflate(R.layout.tab_indicator,
				null);
		TextView tv = (TextView) view.findViewById(R.id.tv_tab);
		ImageView iv=(ImageView)view.findViewById(R.id.imageView1);
		iv.setBackgroundResource(drawable);
		tv.setText(text);
		return view;
	}
	 @Override  
	    public void onBackPressed() {   
	        //把后退事件交给子Activity处理  
			Intent intent = new Intent(charmActivity.this, ViewTestActivity.class);  
	        // 把Activity转换成一个Window，然后转换成View  
	        Window w = SecondGroupTab.group.getLocalActivityManager()  
	                .startActivity("ViewTestActivity",intent);  
	        View view = w.getDecorView();  
	        //设置要跳转的Activity显示为本ActivityGroup的内容  
	        SecondGroupTab.group.setContentView(view);  
	       
	    } 
	@Override
	public boolean onTouch(View v, MotionEvent event) {
		// TODO Auto-generated method stub
		Log.i("touch","touch");
		 return mGestureDetector.onTouchEvent(event); 
	}
	@Override
	public boolean onDown(MotionEvent e) {
		// TODO Auto-generated method stub
		return false;
	}
	@Override
	public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
			float velocityY) {
		return false;
	}
	@Override
	public void onLongPress(MotionEvent e) {
		// TODO Auto-generated method stub
	}
	@Override
	public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX,
			float distanceY) {
		// TODO Auto-generated method stub
		return false;
	}
	@Override
	public void onShowPress(MotionEvent e) {
		// TODO Auto-generated method stub
	}
	@Override
	public boolean onSingleTapUp(MotionEvent e) {
		// TODO Auto-generated method stub
		return false;
	}
}
